import { requestClient } from '#/api/request';

export namespace DictTypeApi {
  export interface DictType {
    [key: number]: any;
    children?: DictType[];
    dictTypeId: number;
    dictTypeCode: string;
    dictTypeName: string;
    pDictTypeCode: string;
    pDictTypeName: string;
    seq: number;
    memo: string;
    status: 0 | 1;
    createdTime: string;
    createdBy: string;
    lastUpdateTime: string;
    lastUpdateBy: string;
  }
}

/**
 * 获取字典类型列表数据
 */
async function gridDictType() {
  return requestClient.get<Array<DictTypeApi.DictType>>(
    '/system/dict/dicttype/list',
  );
}

/**
 * 创建字典类型
 * @param data 字典类型数据
 */
async function createDictType(
  data: Omit<DictTypeApi.DictType, 'children' | 'dictTypeId'>,
) {
  return requestClient.post('/system/dict/dicttype', data);
}

/**
 * 更新字典类型
 *
 * @param id 字典类型 ID
 * @param data 字典类型数据
 */
async function updateDictType(
  id: number,
  data: Omit<DictTypeApi.DictType, 'children' | 'dictTypeId'>,
) {
  return requestClient.put(`/system/dict/dicttype/${id}`, data);
}

/**
 * 删除字典类型
 * @param id 字典类型 ID
 */
async function deleteDictType(id: number) {
  return requestClient.delete(`/system/dict/dicttype/${id}`);
}

export { createDictType, deleteDictType, gridDictType, updateDictType };
